import org.junit.Test;

import java.io.*;

/**
 * @ClassName Filetest
 * @Description TODO
 * @Author Admin
 * @Date 2021/6/29 16:24
 * @Version 1.0
 */
public class Filetest {
    @Test
    public void testFileReader1(){

            FileReader fr = null;
            FileWriter fw = null;
        try {
            fr = new FileReader(new File("C://Users/Admin/Desktop/彩票.txt"));
            fw = new FileWriter(new File("C://Users/Admin/Desktop/新建文本文档.txt"));
            char[] cbuf = new char[5];
            int len;//记录每次读入到cbuf数组中的字符的个数
            while((len = fr.read(cbuf)) != -1){
                //每次写出len个字符
                fw.write(cbuf,0,len);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fw!=null){
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fr!=null){
                try {
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }





    }
}
